
package main

import "fmt"

func solution(n int, H int, A int, h []int, a []int) int {
	// 筛选可击败的怪物
	var candidates [][2]int
	for i := 0; i < n; i++ {
		if h[i] < H && a[i] < A {
			candidates = append(candidates, [2]int{h[i], a[i]})
		}
	}

	if len(candidates) == 0 {
		return 0
	}

	// 初始化DP数组
	dp := make([]int, len(candidates))
	for i := range dp {
		dp[i] = 1
	}

	// 动态规划求解
	for i := 1; i < len(candidates); i++ {
		for j := 0; j < i; j++ {
			if candidates[i][0] > candidates[j][0] && candidates[i][1] > candidates[j][1] {
				if dp[j]+1 > dp[i] {
					dp[i] = dp[j] + 1
				}
			}
		}
	}

	// 找出最大值
	maxLen := 0
	for _, v := range dp {
		if v > maxLen {
			maxLen = v
		}
	}
	return maxLen
}

func main() {
	fmt.Println(solution(3, 4, 5, []int{1, 2, 3}, []int{3, 2, 1}) == 1)
	fmt.Println(solution(5, 10, 10, []int{6, 9, 12, 4, 7}, []int{8, 9, 10, 2, 5}) == 2)
	fmt.Println(solution(4, 20, 25, []int{10, 15, 18, 22}, []int{12, 18, 20, 26}) == 3)
	fmt.Println(solution(13, 8, 7, 
		[]int{8, 4, 1, 5, 11, 8, 8, 8, 3, 2, 13, 1, 16},
		[]int{16, 7, 6, 7, 8, 1, 9, 14, 14, 3, 12, 14, 11}) == 1)
}
